home *** CD-ROM | disk | FTP | other *** search
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- /* */
- /* MADE - Macintosh Application Development Essentials */
- /* --------------------------------------------------- */
- /* (c) Sig Software, http://www.sigsoftware.com/ */
- /* */
- /* These files can only be used for experimental purposes. To obtain */
- /* fully commented code, source code for the functions in Essential */
- /* Extras.h and permission for usage in final projects, you must */
- /* purchase a license. See documentation for more information. */
- /* */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- /* */
- /* Essential Headers.h */
- /* ------------------- */
- /* */
- /* Prototypes and globals generally used by MADE and your code. */
- /* */
- /* Version 1.0.0 - 10th November 1996 */
- /* Version 1.2.0 - 20th November 1998 - Browser not found error */
- /* Version 1.4.0 - 26th May 1999 - Linked lists, better errors */
- /* */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- #include "User Settings.h" // so you never need to include this manually
-
- /*
- Error stuff
- */
-
- #define System_Software_Version_Error 1996 // use when needed OS is missing
- #define Browser_Not_Found_Error 1997 // returned by URL code
-
- typedef OSErr Error;
-
- void TestError(Error error);
- // displays relevant error dialog if error is non-zero
- Error TestResError(void* resource);
- // checks for zero handle, ResError, shows dialog and returns error code
- Error TestMemError(void* pointer);
- // checks for zero pointer, MemError, shows dialog and returns error code
-
- /*
- About error hiding: for some operations, you will want MADE not to show errors to the user,
- for example when accepting a drag-and-drop. Before beginning these operations, call
- HideErrors() with a pointer to the variable you want to catch errors in instead of showing
- an alert. This lets you call TestError with impunity. HideErrors() can be nested but...
- You MUST call ShowErrors after, and at the same level in your code as HideErrors
- */
-
- Boolean HideErrors(Error* keepError);
- // hide all subsequent errors, catching them in your error variable
- // return true if successful, otherwise abandon the operation
- void ShowErrors();
- // removes the most recently added error hiding
-
- /*
- About error contexts: when MADE reports an error to the user, it can supply additional
- information about what your application was currently doing. The plain error text is
- "An error occurred." - anything you add in will be inserted before the period, for example
- AddErrorContext("\p while saving a file") -> "An error occurred while saving a file."
- You can also nest error contexts in which case the latter added context is prefixed first.
- For example: AddErrorContext("\p while quitting"); AddErrorContext("\p while saving a file");
- will give you "An error occurred while saving a file while quitting." Clever, eh?
- You MUST call RemoveErrorContext after, and at the same level in your code as AddErrorContext
- */
-
- Boolean AddErrorContext(Str255 contextString);
- // add a new error context string for all subsequent error reports
- // return true if successful, otherwise abandon the operation
- void RemoveErrorContext();
- // remove the most recently added error context
-
- /*
- Assertion stuff
-
- The point of assertions is to allow you to put checks into your source code which are performed while
- your project is under development, but which are skipped over in the final release for speed's sake.
- This lets you have extensive, slow, laborious double-checks without burdening your eventual users.
- */
-
- #if Project_Under_Development
-
- void HandleAssertFailure(char* file, char* date, int line); // params shown in dialog
-
- #define Assert(test) { if (!(test)) HandleAssertFailure(__FILE__, __DATE__, __LINE__); }
- // calls failure handler with necessary parameters if text fails
- // NOTE : If Pool Strings is off under CodeWarrior C/C++ this will cause
- // unnecessary code expansion because of all the file names and dates.
- #else
-
- #define Assert(test) ;
- // all Assertions do nothing if project not under development
- #endif
-
- #define AssertRange(test, minimum, maximum) Assert(((test)>=(minimum))&&((test)<=(maximum)));
- // Asserts test is within minimum and maximum values
-
- /*
- Linked list routines
-
- This lets you set up easy linked lists of pointer-allocated memory.
- To use, the data structures to be linked MUST have the next pointer as the
- first 4 bytes. The pointer to the first must also be initialised to 0. See
- error string storage code for an example.
- */
-
- void AddToLinkedList(void** firstPointer, void* addItem, void* beforeItem);
- // add the structure pointed to by addItem to the list starting at *firstPointer
- // before item beforeItem - pass zero to put in at the end
- void RemoveFromLinkedList(void** firstPointer, void* removeItem);
- // removes the item pointed to by removeItem from the list starting at *firstPointer
- // doesn't actually de-allocate the memory for removeItem
- void* GetLinkedListItem(void* firstPointer, long itemNumber);
- // get item number itemNumber from list starting at firstPointer, item number starts from 0
- long CountLinkedListItems(void* firstPointer);
- // counts the number of items in linked list starting at firstPointer
-
- /*
- Memory allocation and destruction routines
- */
-
- void* AllocPtr(Error* error, Size allocate);
- // try to create non-movable memory block
- void** AllocHandle(Error* error, Size allocate);
- // try to create movable memory block
- void DestroyPtr(void* pointer);
- // destroy non-movable memory block
- void DestroyHandle(void** handle);
- // destroy movable memory block
-
- /*
- Memory locking and unlocking routines. Whenever locking or unlocking handlers,
- use these, not the system calls HLock and HUnlock. If the relevant settings are on,
- these will then check the Handle's status actually changes when you lock/unlock it.
- */
-
- #if Project_Under_Development && Assert_Memory_Locking
-
- void LockHandleAssert(void** handle);
- void UnlockHandleAssert(void** handle);
-
- #define LockHandle(handle) LockHandleAssert(handle)
- #define UnlockHandle(handle) UnlockHandleAssert(handle)
- // these versions check the status is changed
- #else
-
- #define LockHandle(handle) HLock((Handle)(handle))
- #define UnlockHandle(handle) HUnlock((Handle)(handle))
- // these versions call the normal Mac Toolbox
- #endif
-
- /*
- Useful miniature labels for catching error conditions five levels deep
- */
-
- #define _e failed:;
- #define _e2 failed2:;
- #define _e3 failed3:;
- #define _e4 failed4:;
- #define _e5 failed5:;
-
- #define _g goto failed;
- #define _g2 goto failed2;
- #define _g3 goto failed3;
- #define _g4 goto failed4;
- #define _g5 goto failed5;
-
- #define _i(p) { if (p) _g }
- #define _i2(p) { if (p) _g2 }
- #define _i3(p) { if (p) _g3 }
- #define _i4(p) { if (p) _g4 }
- #define _i5(p) { if (p) _g5 }
-
- /*
- Crucial global variables
- */
-
- extern Boolean applicationHasQuit; // set high to end event loop
- extern void* dummy; // used for discarding unwanted results
- extern WindowPtr frontWindow; // which Window is in front of the rest
- extern Boolean appInFront; // whether the application is currently in front
- #if Use_Drag_Manager
- extern Boolean hasDragManager; // if the drag manager is installed
- #endif
-
- /*
- Useful functions
- */
-
- Boolean CheckGestaltBit(OSType selector, char bit); // for determining environment
- void ShowResCursor(short cursorID); // loads cursor from resource and displays
- #if Use_Drag_Manager
- void CreateDragRegion(RgnHandle region);
- // Turns the given region in local co-ordinates into a drag frame region in
- // global co-ordinates, using the current active GrafPort. This is very
- // useful for initialising drags with TrackDrag().
- #endif
-